<template>
  <div class="order">
    <div class="box" v-for="(item,index) in orderlist" :key="index" @click="detail(item)">
      <div class="order-info">
        <div class="icon"><img :src="item.image_path" alt=""></div>
        <div class="right">
          <div class="top">
            <div class="name">
              <div class="title">{{item.shopInfoName | fontNumber}}</div>
              <div class="time">{{item.date}}</div>
            </div>
            <div class="order-success">
              订单已完成
            </div>
          </div>
          <div class="bottom">
            <div class="name">{{item.selectFoodsName}}</div>
            <div class="price">¥{{item.totalPrice}}</div>
          </div>
        </div>
      </div>
      <div style="padding-right:.3rem;">
        <div class="aging">再来一单</div>
      </div>
    </div>

  </div>
</template>
<script>
export default {
  name: 'order',
  data () {
    return {
      orderlist: []
    }
  },
  beforeRouteEnter (to, from, next) {
    next(vm => {
      vm.getData();
    });
  },
  created () {
    this.getData();
  },
  methods: {
    getData () {
      const userId = localStorage.getItem('userId')
      this.$axios(`/api/user/orders/${userId}`).then(res => {
        // console.log(res.data);
        this.orderlist = res.data.orderlist;
        console.log(this.orderlist);
      });
    },
    detail (item) {
      this.$router.push({ name: 'orderInfo', params:{orderInfo:item}  })
    }

  },
  filters: {
    fontNumber (date) {
      const length = date.length
      if (length > 8) {
        var str = ''
        str = date.substring(0, 12) + '...'
        return str
      } else {
        return date
      }
    }
  }
}
</script>
<style  scoped>
.order-info {
  display: flex;
  background-color: #fff;
  justify-content: space-between;
  align-items: center;
  padding: 0.1rem 0.3rem 0 0;
  border-bottom: 0.03rem #ccc solid;
  overflow: hidden;
}
.icon {
  margin-bottom: auto;
  margin-right: auto;
  padding-top: 0.2rem;
  padding-right: 0.2rem;
}
.icon img {
  width: 1rem;
}
.name {
  flex: 1;
  margin-left: 0.2rem;
  line-height: 0.5rem;
}
.order-success {
  width: 2rem;
  font-size: 0.3rem;
  font-weight: 550;
  text-align: right;
}
.title {
  font-weight: 550;
}
.time {
  color: rgb(162, 162, 162);
  font-size: 0.2rem;
}
.border {
  border-top: 0.03rem #ccc solid;
  margin-top: 0.3rem;
}
.right {
  flex: 1;
}
.top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 0.03rem #ccc solid;
  padding: 0.2rem 0;
}
.bottom {
  display: flex;
  padding: 0.3rem 0.2rem 0.3rem 0.3rem;
  justify-content: space-between;
}
.price {
  font-size: 0.4rem;
  font-weight: 550;
}
.bottom .name {
  color: rgb(31, 30, 30);
  font-size: 0.3rem;
}
.box {
  /* padding: .3rem; */
  background-color: rgb(255, 255, 255);
  padding: 0 0 0 0.4rem;
  margin-top: 0.3rem;
}
.order,
.box {
  box-sizing: border-box;
  padding-bottom: 0.1rem;
}
.aging {
  color: #009eef;
  border: 0.03rem #009eef solid;
  width: 2rem;
  text-align: center;
  height: 0.6rem;
  line-height: 0.6rem;
  border-radius: 0.1rem;
  margin-top: 0.3rem;
  margin-bottom: 0.3rem;
  margin-left: auto;
}
</style>
